package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.DoctorInfo;
import com.ruoyi.system.service.IDoctorInfoService;
import com.ruoyi.system.service.IServerTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DoctorServer;
import com.ruoyi.system.service.IDoctorServerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专家服务分配Controller
 * 
 * @author ruoyi
 * @date 2021-11-11
 */
@Controller
@RequestMapping("/doctorServer/server")
public class DoctorServerController extends BaseController
{
    private String prefix = "doctorServer/server";

    @Autowired
    private IDoctorServerService doctorServerService;

    @Autowired
    private IDoctorInfoService doctorInfoService;

    @Autowired
    private IServerTypeService serverTypeService;

    @Autowired
    private DoctorServer doctorServer1;

    @RequiresPermissions("doctorServer:server:view")
    @GetMapping()
    public String server()
    {
        return prefix + "/server";
    }

    /**
     * 查询专家服务分配列表
     */
    @RequiresPermissions("doctorServer:server:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DoctorServer doctorServer)
    {
        startPage();
        List<DoctorServer> list = doctorServerService.selectDoctorServerList(doctorServer);
        return getDataTable(list);
    }

    @PostMapping("/list2")
    @ResponseBody
    public AjaxResult list2(DoctorServer doctorServer){
        List<DoctorServer> list = doctorServerService.selectDoctorServerList(doctorServer);
        return AjaxResult.success(list);
    }

    /**
     * 导出专家服务分配列表
     */
    @RequiresPermissions("doctorServer:server:export")
    @Log(title = "专家服务分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DoctorServer doctorServer)
    {
        List<DoctorServer> list = doctorServerService.selectDoctorServerList(doctorServer);
        ExcelUtil<DoctorServer> util = new ExcelUtil<DoctorServer>(DoctorServer.class);
        return util.exportExcel(list, "专家服务分配数据");
    }

    /**
     * 新增专家服务分配
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存专家服务分配
     */
    @RequiresPermissions("doctorServer:server:add")
    @Log(title = "专家服务分配", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DoctorServer doctorServer)
    {
        return toAjax(doctorServerService.insertDoctorServer(doctorServer));
    }

    /**
     * 修改专家服务分配
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DoctorServer doctorServer = doctorServerService.selectDoctorServerById(id);
        mmap.put("doctorServer", doctorServer);
        return prefix + "/edit";
    }

    /**
     * 修改保存专家服务分配
     */
    @RequiresPermissions("doctorServer:server:edit")
    @Log(title = "专家服务分配", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DoctorServer doctorServer)
    {
        return toAjax(doctorServerService.updateDoctorServer(doctorServer));
    }

    /**
     * 删除专家服务分配
     */
    @RequiresPermissions("doctorServer:server:remove")
    @Log(title = "专家服务分配", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(doctorServerService.deleteDoctorServerByIds(ids));
    }
}
